<?php
	class Hukuman_model extends Model{
		function Hukuman_model(){
			parent::Model();
            $this->load->model('Datum_model');      
		}
        
        function list_hukuman($nip="", $where="", $order="", $ro=false) {
              
            if ($nip=="") {
                return "";
            } else {                                                                  
                $id_pegawai = Datum_model::getData('idspg_pegawai','pegawai','nip_baru ="'.$nip.'"');                     
                $id_pegawai = $id_pegawai!=false?$id_pegawai:Datum_model::getData('idspg_pegawai','pegawai','nip ="'.$nip.'"');                     
                
                $this->db->where(array('id_pegawai' => $id_pegawai));
            }
            
            if ($where!='') {
                $this->db->where($where);
            }
            if ($order == "") {
                $this->db->order_by('id_pegawai asc');
            } else {
                $this->db->order_by($order);
            }
            $q = $this->db->get('hukuman');

            $s = "
              <table id=\"scrollable\" width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\" class=\"tbl\">
                <thead>
                  <tr>
                    <th>No</th>
                    
                    <th>Jenis Hukuman </th>
                    <th>Bentuk Hukuman </th>
                    <th>Tanggal</th>
                    
                    ";
            if ($ro==false) {
                $s .= " <th colspan='2'> Aksi </th>";
            }
            $s .= "</tr></thead><tbody>";
			$i = 1;

            $this->load->model('Datum_model');
            foreach($q->result() as $row) {
                if ($i % 2 == 1) {
                    $kelas = "event2";
                } else {
                    $kelas = "event";
                }

                  $id_bentuk = Datum_model::getData('id_jenis_hukuman', 'bentuk_hukuman', array('idspg_bentuk_hukuman' => $row->id_bentuk_hukuman));
				  $jenis = Datum_model::getData('nama', 'jenis_hukuman', array('idspg_jenis_hukuman' => $id_bentuk));
                  $bentuk = Datum_model::getData('nama', 'bentuk_hukuman', array('idspg_bentuk_hukuman' => $row->id_bentuk_hukuman));
                
                $s .= "
              <tr class=\"$kelas\" id=\"row-".$row->idspg_hukuman."\" >
                <td><div align=\"right\">$i.&nbsp;&nbsp;&nbsp;</div></td>
                
                <td>".$jenis."</td>
                <td>".$bentuk."</td>                
                <td>".YMD2DMY(trimTime($row->tanggal), TGL_SEPARATOR)."</td>   
    
                ";
                if ($ro==false) {
                    $s .= "
                    <td><div align='center'> <a href='".base_url()."index.php/hukuman/form_edit/".$row->idspg_hukuman."' title=\"Ubah Data\" class=\"edit\"><img src='".base_url()."images/edit.gif' border='0'></a></div></td>   
                    <td><div align='center'><a href=\"javascript:deleteRow(".$row->idspg_hukuman.")\"><img src='".base_url()."images/del.gif' border='0'></a></div></td>";
                }
                $s .= "
              </tr>";

                $i++;
            }
            $s .= "</tbody></table>";
            return $s;
        }

        function entry_hukuman($form_id, $form_action, $arr=array()) {
        	if (isset($arr['tanggal'])) {
                $a = explode(TGL_SEPARATOR, trimTime($arr['tanggal']));
                $d = $a[2] * 1;
                $m = $a[1] * 1;
                $y = $a[0];
            } else {
                $d = date("j");
                $m = date("n");
                $y = date("Y");
            }
        	
        	$ret = "
			<form action='$form_action' method='post' name='hukuman' id='$form_id'>

                <fieldset >
                 <table class='formTabel' border='0' align='center' cellpadding='5' cellspacing='1'>
                  <tr>
                    <td class='kolom' valign='top'>NIP </td>
                    <td valign='top'>:</td>
                    <td valign='top'>
                    
                      <input name='nip' type='text' id='nip' value='".(isset($arr['nip'])?$arr['nip']:$this->session->userdata('nip'))."' />     
                      <input name='id_pegawai' type='hidden' id='id_pegawai' value='".(isset($arr['id'])?$arr['id']:"")."' />
                       </td>
                  </tr>   
                 <tr>
                    <td class='kolom' valign='top'>Jenis Hukuman </td>
                    <td valign='top'>:</td>
                    <td valign='top'>
                      ".combo_jenis_hukuman('jenis_hukuman',(isset($arr['jenis_hukuman'])?$arr['jenis_hukuman']:""))."
                       </td>
                  </tr>
                  <tr>
                    <td valign='top'>Bentuk Hukuman</td>
                    <td valign='top'>:</td>
                    <td valign='top'>
                      <input name='bentuk_hukuman' type='text' id='bentuk_hukuman' value='".(isset($arr['bentuk_hukuman'])?$arr['bentuk_hukuman']:"")."' size='50' maxlength='150'/>
                      <input name='id_bentuk_hukuman' type='hidden' id='id_bentuk_hukuman' value='".(isset($arr['id_bentuk_hukuman'])?$arr['id_bentuk_hukuman']:"")."' size='11' maxlength='11' /> 
                     </td>
                  </tr>
                  <tr>
                    <td valign='top'>Tanggal</td>
                    <td valign='top'>:</td>
                    <td>".combo_tanggal('d',$d,'')."-".
                      combo_bulan('m',$m,'').
                      "-<input name='y' id='y' type='text' size='6' value='$y'/>
                        <a href=\"#\" id=\"date-pick\">Pilih Tanggal</a>       
                </td>
                  </tr>
                  
                  <tr>
                    <td valign='top'>&nbsp;</td>
                    <td valign='top'>&nbsp;</td>
                    <td valign='top'>
                      <input class=\"tombol\" type=\"button\" name=\"btn_kembali\" id=\"btn_kembali\" value=\"<< Kembali\" />
                  <input class=\"tombol\" type=\"submit\" name=\"button\" id=\"button\" value=\"   Simpan   \" />
                     </td>
                  </tr>
                </table>
               
                </fieldset>

                </form>
			  ";
        	
        	return $ret;
        }

        function simpan($arr, $is_update=false, $id='') {
            if (!$is_update) {
                $this->db->insert('hukuman', $arr);
            } else {
                $this->db->where('idspg_hukuman', $id);
                $this->db->update('hukuman', $arr);
            }
        }
        
	}
?>